<?php

namespace App\Http\Controllers\v1;

use App\Model\CardModel;
use App\Model\CommentModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;

class CommentController extends BaseController
{
    //
    public function getMyComment(Request $request){
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];
        $data = CommentModel::where(['uid'=>$uuid])->get();
        return $this->success('我的评论',$data,200);
    }

    /**
     * 查询评论数量
     * @param Request $request
     * @return CommentController
     */
    public function CommentAllNum(Request $request){
       $cid =  $request -> get('cid');//贴id

        if(empty($cid)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  CardModel()) ->CommentAllNum($cid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

    /**
     * 获取帖子评论用户
     * @param Request $request
     * @return CommentController
     */
    public function CardCommentALLUser(Request $request){
        $cid =  $request -> get('cid');//贴id
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($cid)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  CommentModel()) ->CardCommentALLUser($cid,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

    /**
     * 获取帖子评论详细
     * @param Request $request
     * @return CommentController
     */
    public function CardCommentDesc(Request $request){
        $cid =  $request -> get('cid');//评论id

        if(empty($cid)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  CommentModel()) ->CardCommentDesc($cid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }
//
    /**
     * 获取帖子评论信息详细评论
     * @param Request $request
     * @return CommentController
     */
    public function CardCommentDescCommentDesc(Request $request){
        $cid =  $request -> get('cid');//回复评论id
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($cid)){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  CommentModel()) ->CardCommentDescCommentDesc($cid,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

    /**
     * 贴子评论
     * @param Request $request
     * @return CommentController
     */
    public function CardComment(Request $request){
        $cid = $request ->get('cid');
        $sid = $request ->get('sid');
        $name = $request ->get('name');
        $img = $request ->get('img');
        $rid = $request ->get('rid');
        $centent_image = $request ->get('centent_image');
        $val= $request ->get('val');
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];


        if(empty($name) || empty($img)  ){
            return $this->error('缺少参数！');
        }

        $res = (new CommentModel()) -> CardComment($cid,$sid,$name,$img,$rid,$centent_image,$val,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }

    }

}
